﻿using System;
using System.Data;
using System.IO;

namespace Syno.Core.Output.DataDisplay
{
    public class TemplateDisplay : IDataDisplay
    {
        public string Template { get; set; }
        private INVelocityTemplates _templater;
        public TemplateDisplay()
        {
            _templater = new NVelocityTemplates();
            
        }

        public string Display(DataTable data)
        {
            _templater.AddContext("data", data);
            return _templater.ToString(Template);
        }

        public void AddContext(string id, object data)
        {
             _templater.AddContext(id, data);
        }
    }


    internal class SingleValueResult : IDataDisplay
    {
        public string Display(DataTable data)
        {
            if (data.Columns.Count > 0 && data.Rows.Count > 0)
            {
                return data.Rows[0][0].ToString();
            }
            return "";
        }
    }
}